package com.shiguo365.market.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;


import android.widget.TextView;

import com.shiguo365.market.R;
import com.shiguo365.market.model.Litem;



import java.util.List;

/**
 * 个人中心自定义的适配器
 * Created by caomenglong on 16/7/7.
 */
public class LitemAdapter extends ArrayAdapter<Litem> {

    private int resourceId;

    public LitemAdapter(Context context, int resource, List<Litem> objects) {
        super(context, resource, objects);
        resourceId =resource;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Litem litem=getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder=new ViewHolder();

            viewHolder.litemName= (TextView) view.findViewById(R.id.litemName);
            viewHolder.litemRemark=(TextView) view.findViewById(R.id.litemRemark);
            viewHolder.litemHitNumber =(TextView) view.findViewById(R.id.litemHitNumber);
        }else {
            view =convertView;
            viewHolder=(ViewHolder) view.getTag();
        }

        Log.d("NAME:",litem.getName());
        viewHolder.litemName.setText(litem.getName());
        viewHolder.litemRemark.setText(litem.getRemark());

        viewHolder.litemHitNumber.setText(Integer.toString(litem.getHitNumber()));

        if(litem.getRemark()=="" || litem.getRemark()==null){
            //没有备注 显示数字
            if(litem.getHitNumber()==0){
                viewHolder.litemRemark.setVisibility(View.GONE);
                viewHolder.litemHitNumber.setVisibility(View.GONE);
            }else{
                viewHolder.litemRemark.setVisibility(View.GONE);
                viewHolder.litemHitNumber.setVisibility(View.VISIBLE);
            }

        }else{
            //有备注 显示备注
            viewHolder.litemRemark.setVisibility(View.VISIBLE);
            viewHolder.litemHitNumber.setVisibility(View.GONE);
        }


        return view;
    }


    class ViewHolder{

        TextView litemName;
        TextView litemRemark;
        TextView litemHitNumber;
    }

}
